<?php
/*
 * 企业库 列表页
 * @package    company
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: 6ddffa9b6aebd57b5a49f46d05a53889e6e9b4b8 $
 */
defined('IN_IXDCW') or exit('Access Denied');
require DT_CORE.'/'.$module.'/common.inc.php';
	$head_title = '企业库_';
$buildBase = array('catid', 'areaid' ,'kw');
$group=PCache::read("grouporder.php");//读取缓存会员组排序
if(!$group){
	Xd_save_groupcachefile();
}


if (!empty($CAT)) {
	unset($CAT['moduleid']);
	extract($CAT);
	//制作菜单列表
	$maincat=Xd_get_catlist($CAT,25);
} else {
	$maincat[0] = get_maincat(0, 25);
}

if (!empty($ARE)) {
	$mainarea=Xd_get_arealists($ARE);
} else {
	$mainarea[0] = get_mainarea(0);
}

$filter['catid']  = getgpc('catid');
$filter['areaid'] = getgpc('areaid');


$table = Table::name(Table::NAME_MERCHANT_DOC);
$tableCatid = Table::name(Table::NAME_MERCHANT_CATID);
$sql="select d.did,d.title,d.summary,d.company_areaid,d.company_thumb from $table d,$tableCatid c where ";


$searchSql = " d.did=c.did ";

//关键字
if(isset($kw) && $kw!='')           $searchSql .= " AND d.title LIKE '%$keyword%'";

//类别
if(isset($catid) && $catid!=''){
	$category = PCache::read('category-25.php');
	if($category[$catid]['arrchildid']){
		$categoryid = $category[$catid]['arrchildid'];
		$searchSql .= " AND c.catid IN($categoryid)";
	}else{
		$searchSql .= " AND c.catid IN($catid)";
	}
}

//地区
if(isset($areaid) && $areaid!='')   $searchSql .= ($ARE['child']) ? " AND d.company_areaid IN (".$ARE['arrchildid'].")" : " AND d.company_areaid=$areaid";

//显示权限
$searchSql .= " and d.authority=1";

//推荐权限
$searchSql .= " and d.level=0";

//过滤版本类别
$searchSql .= "  and c.authority=1";

$sql .= $searchSql;

//统计条目
$sqlCount = "SELECT count(distinct(d.did)) as sum FROM $table d,$tableCatid c where $searchSql";

$items = intval($db->getVar($sqlCount, 'sum'));



$pagesize = 20;
$pn = new Pagination();
$sql .= " GROUP BY d.did ORDER BY d.did DESC LIMIT " . ($pn->getPage() - 1) * $pagesize . ',' . $pagesize ;
$companyList = $db->getAll($sql);
//print_r($sql);






$pn->padding(false);
$pn->recordsPerPage($pagesize);
$pn->records($items);

include template('list','company');

